var puntuacion = 0;
		var puntosItems = [0,50,100,500];
		var	bolas = [], barra , blocks=[] , items=[];
		var vConstante = 100;			
		var game = true;
		
		window.addEventListener("load", start, false);

function start(){
	//START
	if(bolas[0]== null){
		canvas = document.getElementById("c");
		context = canvas.getContext("2d");
		w = canvas.width = 500;
		h = canvas.height = 500;
		game = true;
	
		var map=[[0,0,1,1,1,1,1,0,1,1],
			 [0,0,1,1,0,1,1,0,1,0],
			 [0,0,1,1,1,1,1,0,1,1],
			 [1,0,1,1,0,1,1,1,1,1],
			 [1,1,1,1,0,1,0,1,0,1]];
 
		chargeMap(map);
		barra = new Barra();
		bolas.push(new Bola());
		window.setInterval(update , 1000/50);

//RESTART
	}else{
		game = true;
		barra = new Barra();
		bolas.shift();
		bolas.push(new Bola());
	}
}

function update(){
	if(game == true){
		movebolas();
		moveBarra();
		itemsMove();
		colision();
		controls();
		paint();
	}
}

function paint(){
	var i;
	context.fillStyle = "black";
	context.fillRect(0, 0, w, h);
	for( i=0 ; i<bolas.length ; i++){
		context.drawImage(img_bola, bolas[i].x, bolas[i].y,bolas[i].w,bolas[i].h);				
	}
	context.drawImage(img_barra, barra.x, barra.y, barra.w, barra.h);	
	
	for( i=0 ; i<blocks.length ; i++){
		context.drawImage(img_block, blocks[i].x, blocks[i].y, blocks[i].w, blocks[i].h);				
	}
	
	for(i=0; i<items.length ; i++){
		switch(items[i].type){
			case 1:
				context.drawImage(img_fresa, items[i].x, items[i].y, items[i].w, items[i].h);
			break;
				
			case 2:
				context.drawImage(img_manzana, items[i].x, items[i].y, items[i].w, items[i].h);
			break;
			
			case 3:
				context.drawImage(img_estrella, items[i].x, items[i].y, items[i].w, items[i].h);
			break;
		}		
	}
			
	//HUD
	context.font="12px Arial";
	context.fillStyle = 'white';
	context.fillText("Puntos: " + puntuacion,10,480);
	
}

function chargeMap(map){
	var x,y, aux=[];

	for(y=0;y<5;y++){
		for(x=0;x<10;x++){
			aux = map[y];
			if(aux[x]==1){
				blocks.push(new Block(x*50,y*25));
			}
		}
	}
	
}
	
function deleteBlock(posBlock){
	var rand = Math.random()*10 ;
	var FRESA = 1, MANZANA = 2, ESTRELLA = 3;
	switch(Math.floor(rand)){
		case 1:
			items.push(new Item(blocks[posBlock].x, blocks[posBlock].y , FRESA));
		break;
				
		case 2:
			items.push(new Item(blocks[posBlock].x, blocks[posBlock].y , MANZANA));
		break;
		
		case 3:
			items.push(new Item(blocks[posBlock].x, blocks[posBlock].y , ESTRELLA));
		break;
	}
	
	blocks.splice(posBlock,1);
}


function movebolas(){
	for(var i = 0 ; i < bolas.length ; i++){
		bolas[i].move();
	}
}

function moveBarra(){
	barra.move();
}

function itemsMove(){
	for(var i=0 ; i<items.length ; i++){
		items[i].move();
	}
}	